package org.example.corpus.auth.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.corpus.auth.dao.UserDao;
import org.example.corpus.model.User;
import org.example.corpus.auth.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    @Override
    public User login(String username, String password) {
        User user =userDao.login(username,password);
        return user;
    }

    @Override
    public Integer register(User user) {
        user.setRole("1");
        user.setCreatedAt(new Date());
        user.setUpdatedAt(new Date());
        User select=userDao.check(user.getUsername());
        if(select!=null)
            return 2;
        Integer ret = userDao.insertUser(user);
        return ret;
    }
}
